﻿Public Class screenshot

    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles makescreen_btn.Click
        'the working area excludes all docked toolbars like taskbar, etc.
        Dim currentScreen = Screen.FromHandle(Me.Handle).WorkingArea

        'create a bitmap of the working area
        Using bmp As New Bitmap(currentScreen.Width, currentScreen.Height)

            'copy the screen to the image
            Using g = Graphics.FromImage(bmp)
                g.CopyFromScreen(New Point(0, 0), New Point(0, 0), currentScreen.Size)
            End Using

            'save the image

            Using sfd As New SaveFileDialog() With {.Filter = "PNG Image|*.png",
                                                    .InitialDirectory = My.Computer.FileSystem.SpecialDirectories.MyDocuments}
                sfd.FileName = "Screenshot_" + Date.Today()
                sfd.OverwritePrompt = True
                sfd.Title = "Bestand opslaan..."
                If sfd.ShowDialog() = Windows.Forms.DialogResult.OK Then
                    bmp.Save(sfd.FileName, System.Drawing.Imaging.ImageFormat.Png)
                End If
                Me.Close()
            End Using
        End Using
    End Sub
End Class